package com.example.demo.controller;

import com.example.demo.model.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/blog")
public class BlogRequestController {
    @RequestMapping("/hello")
    public String hello(){
        return "hello world!";
    }
    @RequestMapping(value = "/getParam", method = RequestMethod.GET)
    public String getParam(@RequestParam(value = "name",required = false) String param){
        return "接收到参数：" + param;
    }
    @RequestMapping("/getArray")
    public String getList(String[] array){
        return Arrays.toString(array);
    }
    @RequestMapping("/getList")
    public String getList(@RequestParam("list") List<String> list){
        return "接收到参数 list:" + list;
    }
    @RequestMapping("getJson")
    public String getJson(@RequestBody Student student){
        return student.toString();
    }
    @RequestMapping("/article/{articleId}")
    public String getArticleId(@PathVariable("articleId") Integer id){
        return "articleId=" + id;
    }
    @RequestMapping("/uploadFile")
    public String uploadFile(@RequestPart("file") MultipartFile file){
        return "接收到文件，文件名称：" + file.getOriginalFilename();
    }
}
